<?php
/**
 * Created by PhpStorm.
 * User: Edward
 * Date: 2019/5/30
 * Time: 13:51
 */

namespace app\lib\exception;

use  think\exception\Handle;
use think\facade\Request;

class ExceptionHandler extends Handle{
    private $code;
    private $msg;
    private $errCode;

    public function render(\Exception $e) {
        if($e instanceof BaseException){
            $this->code = $e->code;
            $this->msg = $e->msg;
            $this->errCode = $e->errCode;
        }else{
            if(config('app_debug')){
                return parent::render($e);
            }else{
                $this->code = 500;
                $this->msg ='服务器内部异常，不想告诉你';
                $this->errCode = 999;
            }

        }
        return writeJson($this->code,[],$this->msg,$this->errCode);
    }
}